package com.yss.sofa.report.engine;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import com.yss.sofa.report.engine.cell.meta.MetaCell;
import com.yss.sofa.report.engine.cell.page.PageCell;
import com.yss.sofa.report.engine.cell.visible.VisibleCell;


public class Template implements Serializable{
	private static final long serialVersionUID = -2645945181096983826L;
	private byte[] middle;
	private MetaCell mainMeta;
	private MetaCell formMeta;
	private Map<String,PageCell> mainPages=new LinkedHashMap<String, PageCell>();
	private PageCell formPage;
	private Set<Parameter> mainParams=new HashSet<Parameter>();
	private Set<Parameter> formParams=new HashSet<Parameter>();
	private Set<DataSet> mainDatasets=new HashSet<DataSet>();
	private Set<DataSet> formDatasets=new HashSet<DataSet>();
	private Map<String,LinkedHashSet<VisibleCell>> mainCells=new LinkedHashMap<String,LinkedHashSet<VisibleCell>>();
	private Set<VisibleCell> formCells=new LinkedHashSet<VisibleCell>();
	private String html=null;//sheet[style] to html
	private boolean hasStyle=false;//是否有sheet[style]
	private ArrayList[] mainPicDataSetsOffset;
	private List<Entry<String,Integer>> dataSetsRows=new ArrayList<Entry<String,Integer>>();
	private String customTemplateType;
	public DataSet getMainDataSet(String code){
		for(DataSet ds:mainDatasets){
			if(ds.getCode().equals(code)){
				return ds;
			}
		}
		return null;
	}
	public DataSet getFormDataSet(String code){
		for(DataSet ds:formDatasets){
			if(ds.getCode().equals(code)){
				return ds;
			}
		}
		return null;
	}

	public Set<Parameter> getMainParams() {
		return mainParams;
	}

	public void setMainParams(Set<Parameter> mainParams) {
		this.mainParams = mainParams;
	}
	
	public Set<Parameter> getFormParams() {
		return formParams;
	}

	public void setFormParams(Set<Parameter> formParams) {
	}

	public Set<DataSet> getMainDatasets() {
		return mainDatasets;
	}
	public Set<DataSet> getFormDatasets() {
		return formDatasets;
	}

	public void setMainDatasets(Set<DataSet> mainDatasets) {
		this.mainDatasets = mainDatasets;
	}
	public void setFormDatasets(Set<DataSet> formDatasets) {
		this.formDatasets = formDatasets;
	}

	public Set<VisibleCell> getMainCells(String sheet) {
		return mainCells.get(sheet);
	}
	private Template(){
		super();
	}
	public Template(byte[] middle){
		this();
		this.middle=middle;
	}

	public byte[] getMiddle() {
		return middle;
	}

	public Set<VisibleCell> getFormCells() {
		return formCells;
	}
	public PageCell getMainPage(String name) {
		return mainPages.get(name);
	}
	public Template addMain(String name,PageCell page,Collection<VisibleCell> cells) {
		this.mainPages.put(name, page);
		this.mainCells.put(name, new LinkedHashSet<VisibleCell>(cells));
		return this;
	}
	public PageCell getFormPage() {
		return formPage;
	}
	public void setFormPage(PageCell formPage) {
		this.formPage = formPage;
	}
	public MetaCell getMainMeta() {
		return mainMeta;
	}
	public void setMainMeta(MetaCell mainMeta) {
		this.mainMeta = mainMeta;
	}
	public MetaCell getFormMeta() {
		return formMeta;
	}
	public void setFormMeta(MetaCell formMeta) {
		this.formMeta = formMeta;
	}
	public boolean isHasStyle() {
		return hasStyle;
	}
	public void setHasStyle(boolean hasStyle) {
		this.hasStyle = hasStyle;
	}
	public String getHtml() {
		return html;
	}
	public void setHtml(String html) {
		this.html = html;
	}
	public Set<String> getMainSheetNames(){
		return this.mainPages.keySet();
	}
	public ArrayList[] getMainPicDataSetsOffset() {
		return mainPicDataSetsOffset;
	}
	public void setMainPicDataSetsOffset(ArrayList[] mainPicDataSetsOffset) {
		this.mainPicDataSetsOffset = mainPicDataSetsOffset;
	}
	public List<Entry<String, Integer>> getDataSetsRows() {
		return dataSetsRows;
	}
	public void setDataSetsRows(List<Entry<String, Integer>> dataSetsRows) {
		this.dataSetsRows = dataSetsRows;
	}
	public String getCustomTemplateType() {
		return customTemplateType;
	}
	public void setCustomTemplateType(String customTemplateType) {
		this.customTemplateType = customTemplateType;
	}
}
